﻿using System;
namespace CourseExamples
{
    public class C04_Recurssion: TestBase
    {
        public int times = 0;
        public C04_Recurssion()
        {
        }

        public override void Run()
        {
            for (int n = 1; n <= 10; n++)
                Console.WriteLine($"{n}! = {f1(n)}");
            hanoi(10, 'A', 'B', 'C');    // n = 10, total step 1023  2^n - 1
            Console.WriteLine("total steps: " + steps);
        }

        public int steps = 0;
        // A: start pole, B: temp pole, C: target Pole
        public void hanoi(int n, char A, char B, char C)
        {
            if (n > 0)
            {
                hanoi(n - 1, A, C, B);
                Console.WriteLine($"Move {A} -> {C}");
                steps++;
                hanoi(n - 1, B, A, C);
            }
        }

        public void test1()
        {
            // ch01_basics.Run();
            // new C02_DataStructure().Run();
            new C03_Brute_Force().Run();

            times++;
            Console.WriteLine($"times: {times}");

            //if (times >= 3)
            //    return;


            test1();

            Console.WriteLine("completed");
        }

        public int factorial(int n)
        {
            int result = 1;
            for (int i = 1; i <= n; i++)
            {
                result *= i; // equivalent to result = result * i
            }

            return result;
        }


        public int f1(int n)
        {
            return n > 1 ? f1(n - 1) * n : 1;
        }

    }
}

